home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SETUP2.ASM < prev    next >
Assembly Source File  |  1989-03-06  |  42KB  |  1,355 lines

  1. ;=============================================================================
  2. ; SETUP 2.0 allows text and control codes to be sent directly to a printer
  3. ; from the command line or from within a popup menu window.  Syntax is:
  4. ;
  5. ;    SETUP2 [d:][path][filename] | [/C codes] | [/U]
  6. ;
  7. ; where filename = Name of PMF file
  8. ;    /C = Codes to be sent from the command line
  9. ;       /U = Uninstall the program
  10. ;=============================================================================
  11.  
  12. code        segment    para public 'code'
  13.         assume    cs:code
  14.         org    100h
  15. begin:        jmp    initialize
  16.  
  17. program        db    "SETUP 2.0 "
  18. copyright    db    "(c) 1989 Ziff Communications Co.",13,10
  19. author        db    "PC Magazine ",254," Jeff Prosise",13,10
  20. hotkey        db    "Hotkey is Ctrl-Rt/Shift",13,10,"$",1Ah
  21.  
  22. videocols    db    ?            ;number of columns displayed
  23. videopage    db    ?            ;active video page
  24. videoseg    dw    ?            ;video segment
  25. videostart    dw    ?            ;starting video address
  26. videocursormode    dw    ?            ;cursor description
  27. videocursorpos    dw    ?            ;BIOS cursor position
  28.  
  29. pname        db    26 dup (20h)        ;menu window title
  30. lpt_number    dw    0            ;LPT port number
  31. status        db    0            ;program status flag
  32. int9h        dd    ?            ;interrupt 9h vector
  33. window_start    label word
  34. window_x    db    ?            ;starting window column
  35. window_y    db    1            ;starting window row
  36. window_end    dw    ?            ;lower right window corner
  37. border_attr    db    ?            ;border color
  38. menu_attr    db    ?            ;window color
  39. hilite_attr    db    ?            ;highlight color
  40. cursor_def    dw    ?            ;default cursor definition
  41. index        db    0            ;menu selection index
  42. ten        db    10            ;base 10 divisor
  43. linecount    dw    0            ;number of menu lines
  44. pagecount    db    1            ;number of menu pages
  45. menupage    db    0            ;current menu page
  46. code_table    dw    offset menu_table    ;address of control code table
  47. end_offset    dw    offset menu_table    ;ending program address
  48.  
  49. ;=============================================================================
  50. ; KBINT receives control when an interrupt 9 is generated.
  51. ;=============================================================================
  52. kbint        proc    far
  53.         pushf                ;call BIOS keyboard routine
  54.         call    int9h
  55.         sti                ;enable interrupts
  56.         push    ax
  57.         mov    ah,2            ;get shift key status
  58.         int    16h
  59.         and    al,0Fh            ;mask off upper four bits
  60.         cmp    al,5            ;was the hotkey combo pressed?
  61.         pop    ax
  62.         jne    kb_exit            ;no, then exit
  63.         cmp    status,0        ;check program status
  64.         jne    kb_exit            ;exit if it's already up
  65.         call    main            ;pop up the window
  66. kb_exit:    iret                ;exit
  67. kbint        endp
  68.  
  69. ;=============================================================================
  70. ; MAIN is the main body of the program.
  71. ;=============================================================================
  72. main        proc    near
  73.         mov    status,1        ;set program status flag
  74.         push    ax            ;save all registers
  75.         push    bx
  76.         push    cx
  77.         push    dx
  78.         push    bp
  79.         push    si
  80.         push    di
  81.         push    ds
  82.         push    es
  83.         mov    ah,15            ;abort if the current video
  84.         int    10h            ;  mode is not a text mode
  85.         cmp    al,7
  86.         je    main1
  87.         cmp    al,4
  88.         jb    main1
  89. ;
  90. ;Restore register values and return to caller.
  91. ;
  92. main_exit:    pop    es            ;restore registers
  93.         pop    ds
  94.         pop    di
  95.         pop    si
  96.         pop    bp
  97.         pop    dx
  98.         pop    cx
  99.         pop    bx
  100.         pop    ax
  101.         mov    status,0        ;clear program status flag
  102.         ret
  103. ;
  104. ;Save video parameters and read the cursor address from the CRT controller.
  105. ;
  106. main1:        push    cs            ;establish DS addressability
  107.         pop    ds            ;  by pointing it to the
  108.         assume    ds:code            ;  code segment
  109.         cld                ;clear DF for string ops
  110.         mov    videocols,ah        ;save columns displayed
  111.         mov    videopage,bh        ;save active video page
  112.         mov    ah,3            ;get cursor information
  113.         int    10h
  114.         mov    videocursormode,cx    ;save cursor mode
  115.         mov    videocursorpos,dx    ;save cursor position
  116.         mov    ax,40h            ;point ES to the BIOS
  117.         mov    es,ax            ;  data area
  118.         mov    dx,es:[4Eh]        ;save video start address
  119.         mov    videostart,dx
  120. ;
  121. ;Define monochrome or color video attributes.
  122. ;
  123.         test    byte ptr es:[63h],40h    ;branch if this is
  124.         jnz    colorvideo        ;  a color system
  125.         mov    videoseg,0B000h        ;monochrome attributes
  126.         mov    border_attr,70h
  127.         mov    menu_attr,07h
  128.         mov    hilite_attr,70h
  129.         mov    cursor_def,0C0Dh
  130.         jmp    short vsave
  131. colorvideo:    mov    videoseg,0B800h        ;color attributes
  132.         mov    border_attr,70h
  133.         mov    menu_attr,4Fh
  134.         mov    hilite_attr,70h
  135.         mov    cursor_def,0607h
  136. ;
  137. ;Save video memory underlying the menu window, then open the window.
  138. ;
  139. vsave:        mov    ah,1            ;hide the cursor
  140.         mov    ch,20h
  141.         int    10h
  142.         mov    cl,videocols        ;determine window position
  143.         sub    cl,32
  144.         mov    window_x,cl        ;save starting column number
  145.         mov    ch,window_y
  146.         mov    dx,cx
  147.         add    dx,101Dh        ;save coordinates of lower
  148.         mov    window_end,dx        ;  right window corner
  149.         push    cs            ;point ES:DI to screen buffer
  150.         pop    es
  151.         mov    di,offset screen_buffer
  152.         mov    ax,offset udr_vio2mem    ;call SCANREGION routine to
  153.         mov    cx,window_start        ;  buffer the contents of
  154.         mov    dx,window_end        ;  video memory
  155.         call    scanregion
  156.         call    openwindow        ;open printer menu window
  157.         mov    al,hilite_attr        ;draw menu selection bar
  158.         call    drawmenubar
  159. ;
  160. ;Monitor the keyboard for keystrokes and act upon the ones received.
  161. ;
  162. keyloop:    mov    ah,0            ;get a keystroke
  163.         int    16h
  164.         or    al,al            ;branch on extended keycodes
  165.         jz    functionkey
  166. ;
  167. ;Output control codes if ENTER was pressed.
  168. ;
  169.         cmp    al,13            ;check for ENTER keycode
  170.         jne    escape
  171.         call    outputlpt        ;output indexed control codes
  172.         jmp    keyloop            ;return to input loop
  173. ;
  174. ;Close the window and exit if ESC was pressed.
  175. ;
  176. escape:        cmp    al,27            ;check for ESC keycode
  177.         jne    slash
  178.         jmp    close            ;jump to exit routines
  179. ;
  180. ;Jump down to the input line if the slash key was pressed.
  181. ;
  182. slash:        cmp    al,"/"            ;check for slash character
  183.         jne    keyloop            ;ignore anything else
  184.         mov    al,menu_attr        ;blank the menu bar
  185.         call    drawmenubar
  186.         call    scanline        ;read input and send to LPT
  187.         mov    al,hilite_attr        ;redraw the menu bar
  188.         call    drawmenubar
  189.         jmp    keyloop            ;loop back for more
  190. ;
  191. ;Send the corresponding control codes if a function key was pressed.
  192. ;
  193. functionkey:    cmp    ah,59            ;determine whether or not a
  194.         jb    keyloop            ;  function key was pressed
  195.         cmp    ah,68
  196.         ja    up_arrow
  197.         push    ax            ;save extended keycode
  198.         mov    al,menu_attr        ;erase the menu bar
  199.         call    drawmenubar
  200.         pop    ax            ;recover keycode
  201.         sub    ah,59            ;calculate new INDEX value
  202.         mov    index,ah
  203.         mov    al,hilite_attr        ;draw new menu bar
  204.         call    drawmenubar
  205.         call    outputlpt        ;output corresponding codes
  206.         jmp    keyloop            ;return to input loop
  207. ;
  208. ;Move the menu bar up one line if up-arrow was pressed.
  209. ;
  210. up_arrow:    cmp    ah,72            ;check for up-arrow
  211.         jne    dn_arrow
  212.         mov    al,menu_attr        ;erase the menu bar
  213.         call    drawmenubar
  214.         dec    index            ;decrement INDEX and wrap
  215.         jns    newbar            ;  if necessary
  216.         mov    index,9
  217. newbar:        mov    al,hilite_attr        ;redraw the menu bar
  218.         call    drawmenubar
  219.         jmp    keyloop            ;return to input loop
  220. ;
  221. ;Move the menu bar down one line if down-arrow was pressed.
  222. ;
  223. dn_arrow:    cmp    ah,80            ;check for down-arrow
  224.         jne    pgup
  225.         mov    al,menu_attr        ;erase the menu bar
  226.         call    drawmenubar
  227.         inc    index            ;increment INDEX and wrap
  228.         cmp    index,10        ;  around if necessary
  229.         jne    newbar            ;jump to finish up
  230.         mov    index,0
  231.         jmp    newbar
  232. ;
  233. ;Flip to the preceding menu page if PgUp was pressed.
  234. ;
  235. pgup:        cmp    ah,73            ;check for PgUp
  236.         jne    pgdn
  237.         cmp    pagecount,1        ;ignore if there is only
  238.         je    retkey            ;  one menu
  239.         dec    menupage        ;set MENUPAGE to previous
  240.         jns    newpage            ;  page and wrap around
  241.         mov    al,pagecount        ;  if necessary
  242.         dec    al
  243.         mov    menupage,al
  244. newpage:    call    writemenu        ;write text of page to memory
  245.         mov    al,hilite_attr        ;redraw the menu bar
  246.         call    drawmenubar
  247. retkey:        jmp    keyloop            ;return to input loop
  248. ;
  249. ;Flip to the next page if PgDn was pressed.
  250. ;
  251. pgdn:        cmp    ah,81            ;check for PgDn
  252.         jne    retkey
  253.         cmp    pagecount,1        ;ignore if there is only
  254.         je    retkey            ;  one menu
  255.         inc    menupage        ;adjust MENUPAGE
  256.         mov    al,pagecount
  257.         cmp    menupage,al
  258.         jne    newpage            ;jump to finish up
  259.         mov    menupage,0
  260.         jmp    newpage
  261. ;
  262. ;Close the menu window.
  263. ;
  264. close:        mov    si,offset screen_buffer    ;point SI to buffer
  265.         mov    ax,offset udr_mem2vio    ;call SCANREGION routine to
  266.         mov    cx,window_start        ;  restore the contents of
  267.         mov    dx,window_end        ;  video memory
  268.         call    scanregion
  269. ;
  270. ;Restore the cursor mode and position, then